package main

import "fmt"

type Student struct {
	id   int
	name string
	sex  byte
	age  int
	addr string
}

func main() {
	//1.顺序初始化,必须每个成员都初始化
	var s1 Student = Student{1, "mike", 'm', 18, "sz"}
	s2 := Student{2, "yoyo", 'f', 20, "sz"}

	//2.指定初始化某个成员,没有初始化的成员为零值
	s4 := Student{id: 2, name: "lily"}
	fmt.Println(s1, s2, s4)

	var s5 *Student = &Student{3, "xiaoming", 'm', 16, "bj"}
	s6 := &Student{4, "rocco", 'm', 3, "sh"}
	fmt.Println(s5, s6)

	fmt.Printf("id=%d,name=%s,sex=%c,age=%d,addr=%s\n", s1.id, s1.name, s1.sex, s1.age, s1.addr)

	//成员变量赋值
	var s7 Student
	s7.id = 2
	s7.name = "yoyo"
	s7.sex = 'f'
	s7.age = 17
	s7.addr = "gz"
	fmt.Println(s7)

	//先分配空间,再赋值
	s8 := new(Student)
	s8.id = 3
	s8.name = "xxx"
	fmt.Println(s8)

	//普通变量和指针变量类型打印
	var p *Student = &s4
	p.id = 5
	(*p).id = 6
	(*p).name = "zzz"
	fmt.Println(p, *p, s4)

	var s9 Student = Student{11, "mike", 'm', 18, "sz"}
	fmt.Println(s1 == s9)
}
